from django.shortcuts import HttpResponse
# from aaa.tasks import x1
import datetime
from aaa import tasks,models

# def create_task(request):
#     print('请求来了')
#     # 1.立即执行
#     result = x1.delay(2,2)

    # 2.定时执行
    # 获取本地时间
    # ctime = datetime.datetime.now()
    # # 本地时间转换成utc时间
    # utc_ctime = datetime.datetime.utcfromtimestamp(ctime.timestamp())
    # target_time = utc_ctime + datetime.timedelta(seconds=10)
    # result = x1.apply_async(args=[11, 3], eta=target_time)
    #
    # print('执行完毕')
    # return HttpResponse(result.id)

# def get_result(request):
#     nid = request.GET.get('nid')
#     from celery.result import AsyncResult
#     # from demos.celery import app
#     from drf2 import celery_app
#     result_object = AsyncResult(id=nid, app=celery_app)
#     ult_object.forget()  # 把数据在backend中移除。

def auction_add(request):
    ctime = datetime.datetime.now()
    utc_ctime = datetime.datetime.utcfromtimestamp(ctime.timestamp())
    target_time = utc_ctime + datetime.timedelta(seconds=10)
    print('auction_add 111')
    task_id = tasks.modify_mgstate.apply_async(args=['wusir'],eta=target_time).id
    #创建定时任务
    models.AuctionTask.objects.create(
        # userinfo = models.UserInfo.objects.get(username='wusir'),
        mgstate_task=task_id
    )
    return HttpResponse(task_id)